import type {CEType, Viewer} from "vendor/components/pro-cesium";

import smallImgUrl from "./img/img.png";
import smallElecImgUrl from "./img/elec.png";
import smallDarkImgUrl from "./img/dark.png";
import smallMidnightImgUrl from "./img/midnight.png";
import smallRedalertImgUrl from "./img/redalert.png";
import smallTerImgUrl from "./img/ter.png";

/**
 * 加载高德地图
 */
export const loadGaoDe = (CE: CEType, viewer: Viewer) => {
    let baselayer = CE.ImageryLayerFactory.createAmapImageryLayer()
    viewer.addBaseLayer(baselayer, {
        iconUrl: smallElecImgUrl,
        name: '电子'
    })

    let baselayer_img = CE.ImageryLayerFactory.createAmapImageryLayer({
        style: 'img'
    })
    viewer.addBaseLayer(baselayer_img, {
        iconUrl: smallImgUrl,
        name: '地图'
    })

    let baselayer_cva = CE.ImageryLayerFactory.createAmapImageryLayer({
        style: 'cva'
    })
    viewer.addBaseLayer([baselayer_img, baselayer_cva], {
        iconUrl: smallImgUrl,
        name: '地图'
    })

    viewer.zoomToPosition(
        new CE.Position(105.565571, 31.984708, 15362816, 0, -90)
    )
}

/**
 * 加载高德地图(无偏移)
 */
export const loadGaoDeNoDeviation = (CE: CEType, viewer: Viewer) => {
    let baselayer = CE.ImageryLayerFactory.createAmapImageryLayer(
        {
            crs:'WGS84'
        }
    )
    viewer.addBaseLayer(baselayer, {
        iconUrl: smallElecImgUrl,
        name: '电子'
    })

    let baselayer_img = CE.ImageryLayerFactory.createAmapImageryLayer({
        style: 'img',
        crs:'WGS84'
    })
    viewer.addBaseLayer(baselayer_img, {
        iconUrl: smallImgUrl,
        name: '地图'
    })

    let baselayer_cva = CE.ImageryLayerFactory.createAmapImageryLayer({
        style: 'cva',
        crs:'WGS84'
    })
    viewer.addBaseLayer([baselayer_img, baselayer_cva], {
        iconUrl: smallImgUrl,
        name: '地图'
    })

    let layer = new CE.TilesetLayer('layer')
    viewer.addLayer(layer)
    let tileset = new CE.Tileset(
        '//resource.dvgis.cn/data/3dtiles/dayanta/tileset.json'
    )
    tileset.setHeight(-420)
    layer.addOverlay(tileset)
    viewer.flyTo(tileset)
}

/**
 * 加载腾讯地图
 */
export const loadTencent = (CE: CEType, viewer: Viewer) => {
    let baselayer_img = CE.ImageryLayerFactory.createTencentImageryLayer({
        style:'img'
    })
    let baselayer_vec = CE.ImageryLayerFactory.createTencentImageryLayer({
        style: 2
    })
    viewer.addBaseLayer([baselayer_img,baselayer_vec], {
        name: '影像',
        iconUrl: smallImgUrl
    })

    let baselayer = CE.ImageryLayerFactory.createTencentImageryLayer()
    viewer.addBaseLayer(baselayer, {
        name: '经典',
        iconUrl: smallElecImgUrl
    })

    let baselayer_2 = CE.ImageryLayerFactory.createTencentImageryLayer({
        style: 4
    })
    viewer.addBaseLayer(baselayer_2, {
        name: '墨渊',
        iconUrl: smallDarkImgUrl
    })

    let baselayer_3 = CE.ImageryLayerFactory.createTencentImageryLayer({
        style: 8
    })
    viewer.addBaseLayer(baselayer_3, {
        name: '白浅',
        iconUrl: smallElecImgUrl
    })

    viewer.zoomToPosition(
        new CE.Position(105.565571, 31.984708, 15362816, 0, -90)
    )
}

/**
 * 加载ArcGis地图
 */
export const loadArcGis = (CE: CEType, viewer: Viewer) => {
    let baselayer = CE.ImageryLayerFactory.createArcGisImageryLayer({
        url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
    })
    viewer.addBaseLayer(baselayer, {
        iconUrl: smallImgUrl,
        name: '影像'
    })

    let baselayer_shaded = CE.ImageryLayerFactory.createArcGisImageryLayer({
        url: 'https://services.arcgisonline.com/arcgis/rest/services/World_Shaded_Relief/MapServer'
    })
    viewer.addBaseLayer(baselayer_shaded, {
        iconUrl: smallElecImgUrl,
        name: '电子'
    })

    let baselayer_street = CE.ImageryLayerFactory.createArcGisImageryLayer({
        url: 'https://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map/MapServer'
    })
    viewer.addBaseLayer(baselayer_street, {
        iconUrl: smallTerImgUrl,
        name: '地形'
    })

    let baselayer_ter = CE.ImageryLayerFactory.createArcGisImageryLayer({
        url: 'https://services.arcgisonline.com/arcgis/rest/services/World_Terrain_Base/MapServer'
    })
    viewer.addBaseLayer(baselayer_ter, {
        iconUrl: smallTerImgUrl,
        name: '地形'
    })

    viewer.zoomToPosition(
        new CE.Position(105.565571, 31.984708, 15362816, 0, -90)
    )
}

/**
 * 加载google地图
 */
export const loadGoogle = (CE: CEType, viewer: Viewer) => {
    let baseLayer = CE.ImageryLayerFactory.createGoogleImageryLayer({
        style: 'img'
    })
    viewer.addBaseLayer(baseLayer)
}

/**
 * 加载xyz瓦片坐标信息
 */
export const loadXYZCoordinates = (CE: CEType, viewer: Viewer) => {
    let baseLayer = CE.ImageryLayerFactory.createCoordImageryLayer()
    viewer.addBaseLayer(baseLayer)
}

/**
 * 加载天地图
 */
export const loadTianDiTu = (CE: CEType, viewer: Viewer) => {
    let key = '0f7c1d161d7352116a21aacf0e9f44c1'
    let cva = CE.ImageryLayerFactory.createTdtImageryLayer({
        key,
        style: 'cva'
    })

    let vec = CE.ImageryLayerFactory.createTdtImageryLayer({
        key
    })

    let img = CE.ImageryLayerFactory.createTdtImageryLayer({
        key,
        style: 'img'
    })

    let ter = CE.ImageryLayerFactory.createTdtImageryLayer({
        key,
        style: 'ter'
    })

    viewer.addBaseLayer(img, {
        name: '影像',
        iconUrl: 'examples/images/icon/img.png'
    })

    viewer.addBaseLayer([img, cva], {
        name: '影像',
        iconUrl: 'examples/images/icon/img.png'
    })

    viewer.addBaseLayer([vec, cva], {
        name: '电子',
        iconUrl: 'examples/images/icon/elec.png'
    })

    viewer.addBaseLayer([ter, cva], {
        name: '地形',
        iconUrl: 'examples/images/icon/ter.png'
    })


    viewer.zoomToPosition(
        new CE.Position(105.565571, 31.984708, 15362816, 0, -90)
    )
}

/**
 * 加载百度地图
 */
export const loadBaiDu = (CE: CEType, viewer: Viewer) => {
    let baselayer_img = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style:'img'
    })

    let baselayer_vec = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style:'vec'
    })

    viewer.addBaseLayer([baselayer_img,baselayer_vec], {
        iconUrl: smallImgUrl,
        name: '影像'
    })


    let baselayer = CE.ImageryLayerFactory.createBaiduImageryLayer()
    let baselayer_traffic = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style:'traffic'
    })
    viewer.addBaseLayer([baselayer,baselayer_traffic], {
        iconUrl: smallElecImgUrl,
        name: '电子'
    })

    let baselayer_dark = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style: 'dark'
    })
    viewer.addBaseLayer(baselayer_dark, {
        iconUrl: smallDarkImgUrl,
        name: '黑夜'
    })

    let baselayer_googlelite = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style: 'googlelite'
    })
    viewer.addBaseLayer(baselayer_googlelite, {
        iconUrl: smallElecImgUrl,
        name: '精简'
    })

    let baselayer_midnight = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style: 'midnight'
    })
    viewer.addBaseLayer(baselayer_midnight, {
        iconUrl: smallMidnightImgUrl,
        name: '午夜蓝'
    })

    let baselayer_redalert = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style: 'redalert'
    })

    viewer.addBaseLayer(baselayer_redalert, {
        iconUrl: smallRedalertImgUrl,
        name: '红色警戒'
    })

    viewer.zoomToPosition(
        new CE.Position(105.565571, 31.984708, 15362816, 0, -90)
    )
}

/**
 * 加载百度地图(无偏移)
 */
export const loadBaiDuNoDeviation = (CE: CEType, viewer: Viewer) => {
    let baselayer_img = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style:'img',
        crs:'WGS84'
    })

    let baselayer_vec = CE.ImageryLayerFactory.createBaiduImageryLayer({
        style:'vec',
        crs:'WGS84'
    })

    // viewer.addBaseLayer([baselayer_img,baselayer_vec], {
    //     iconUrl: smallImgUrl,
    //     name: '影像',
    // })
    //
    //
    // let baselayer = CE.ImageryLayerFactory.createBaiduImageryLayer({
    //     crs:'WGS84'
    // })

    // viewer.addBaseLayer(baselayer, {
    //     iconUrl: smallElecImgUrl,
    //     name: '电子'
    // })
    //
    // let baselayer_dark = CE.ImageryLayerFactory.createBaiduImageryLayer({
    //     style: 'dark',
    //     crs:'WGS84'
    // })
    // viewer.addBaseLayer(baselayer_dark, {
    //     iconUrl: smallDarkImgUrl,
    //     name: '黑夜'
    // })
    //
    // let baselayer_googlelite = CE.ImageryLayerFactory.createBaiduImageryLayer({
    //     style: 'googlelite',
    //     crs:'WGS84'
    // })
    // viewer.addBaseLayer(baselayer_googlelite, {
    //     iconUrl: smallElecImgUrl,
    //     name: '精简'
    // })
    //
    // let baselayer_midnight = CE.ImageryLayerFactory.createBaiduImageryLayer({
    //     style: 'midnight',
    //     crs:'WGS84'
    // })
    // viewer.addBaseLayer(baselayer_midnight, {
    //     iconUrl: smallMidnightImgUrl,
    //     name: '午夜蓝'
    // })
    //
    // let baselayer_redalert = CE.ImageryLayerFactory.createBaiduImageryLayer({
    //     style: 'redalert',
    //     crs:'WGS84'
    // })
    //
    // viewer.addBaseLayer(baselayer_redalert, {
    //     iconUrl: smallRedalertImgUrl,
    //     name: '红色警戒'
    // })

    let layer = new CE.TilesetLayer('layer')
    viewer.addLayer(layer)
    let tileset = new CE.Tileset(
        '//resource.dvgis.cn/data/3dtiles/dayanta/tileset.json'
    )
    tileset.setHeight(-420)
    layer.addOverlay(tileset)
    viewer.flyTo(tileset)
}


